cc.Class({
    extends: cc.Component,

    properties: {
        initIndex: 0, // 负值不初始化状态
        buttonArray: [cc.Button]
    },
    editor: {
        menu: 'UI拓展/RadioButton'
    },

    // use this for initialization
    onLoad: function () {
        this.buttonArray.forEach((button) => {
            button.node.on('click', this.onClick, this);
        });
    },

    start: function() {
        this.initState();
    },
    initState: function() {
        if (this.initIndex >= 0 && this.initIndex < this.buttonArray.length) {
            // this.buttonArray[this.initIndex].node.emit('click');
            this.buttonArray[this.initIndex].node.emit('touchstart');
            this.buttonArray[this.initIndex].node.emit('touchend');
        }
    },
    
    onClick: function(event) {
        var targetButton = event.target.getComponent(cc.Button);
        var self = this;
        this.buttonArray.forEach((button) => {
            if (button === targetButton) {
                button.interactable = false;
            }
            else {
                button.interactable = true;
                if (self.buttonArray.indexOf(button) == 0){
                    cc.Proxy.newburyingPoint(EventConfig.getEventId('投注项（100)'));
                }else if (self.buttonArray.indexOf(button) == 1){
                    cc.Proxy.newburyingPoint(EventConfig.getEventId('投注项（1000)'));
                }else if (self.buttonArray.indexOf(button) == 2){
                    cc.Proxy.newburyingPoint(EventConfig.getEventId('投注项（10000)'));
                }else{
                    cc.Proxy.newburyingPoint(EventConfig.getEventId('投注项（50000)'));
                }
                button.node.emit('click_cancel');
            }
        });
    }
});
